package com.spring.config;

import org.mybatis.spring.SqlSessionFactoryBean;
import org.mybatis.spring.mapper.MapperScannerConfigurer;
import org.springframework.context.annotation.Bean;

import javax.sql.DataSource;

/**
 * @author:CoolTiger
 * @description: TODO
 * @date:2024/05/15/21:52:23
 **/
public class MybatisConfig {
    //配置数据源
    @Bean
    public SqlSessionFactoryBean sqlSessionFactory(DataSource dataSource){
        SqlSessionFactoryBean sf = new SqlSessionFactoryBean();
        sf.setTypeAliasesPackage("com.spring.domain");
        sf.setDataSource(dataSource);
        return sf;
    }
    //配置mapper映射路径
    @Bean
    public MapperScannerConfigurer mapperScanner(){
        MapperScannerConfigurer msc = new MapperScannerConfigurer();
        msc.setBasePackage("com.spring.dao");
        return msc;
    }
}
